"""CreateAdminUserLoginLogTable Migration."""

from masoniteorm.migrations import Migration
import os


class CreateAdminUserLoginLogTable(Migration):
    def up(self):
        """
        Run the migrations.
        """
        with self.schema.create("admin_user_login_logs") as table:
            table.table_comment('管理员登录日志表')
            table.increments("id")
            table.unsigned_integer('admin_user_id', False).comment('admin_user.id')
            table.string('ip', 32, True).comment('IP 地址')
            table.text('other').nullable().comment('其它补充信息')

            table.datetime('created_at', True, True)
            if os.getenv("DB_CONNECTION") != "sqlite":
                table.index('admin_user_id', 'inx_admin_user_id')

    def down(self):
        """
        Revert the migrations.
        """
        self.schema.drop("admin_user_login_logs")
